var ns;
var app = new Vue({
    el: '#app',
    data: {
        UserName: '',
        form: {
            startMonth: 9,
            ProjectID: 0,
            ProjectName: '',
        },
        list: [
            { Name: '已完成任务总数', count: 0, IsBlack: true },
            { Name: '巡检任务数', count: 0, IsBlack: true },
            { Name: '正常完成', count: 0, IsBlack: false },
            { Name: '超时完成', count: 0, IsBlack: false, overtime: 0 },
            { Name: '巡检设备次数', count: 0, IsBlack: false, normalCount: 0, abnormalCount: 0 },
            { Name: '维保任务数', count: 0, IsBlack: true },
            { Name: '正常完成', count: 0, IsBlack: false },
            { Name: '超时完成', count: 0, IsBlack: false, overtime: 0 },
            { Name: '维保设备次数', count: 0, IsBlack: false, normalCount: 0, abnormalCount: 0 },
        ],
        list3: [
            { Name: '已完成设备总数', count: 0, IsBlack: true },
            { Name: '巡检设备次数', count: 0, IsBlack: false, normalCount: 0, abnormalCount: 0 },
            { Name: '维保设备次数', count: 0, IsBlack: false, normalCount: 0, abnormalCount: 0 },
        ],//list3 临时巡查记录数量
        IsShowDate: false,
        minDate: new Date(),
        maxDate: new Date(),
        currentDate: 0,
    },
    methods: {
        formatter(type, val) {
            if (type === 'year') {
                return `${val}年`;
            }
            if (type === 'month') {
                return `${val}月`;
            }
            return val;
        },
        onOpenDate: function () {
            this.IsShowDate = true;
        },
        onCancel: function () {
            this.IsShowDate = false;
        },
        onConfirm(day) {
            var that = this;
            var y = day.getFullYear();
            var m = day.getMonth() + 1;
            var d = day.getDate();
            var h = day.getHours();
            var s = day.getMinutes();
            var nowdate = y + '-' + (m >= 10 ? m : '0' + m);
            that.IsShowDate = false;
            that.form.startMonth = nowdate;
            that.get_data();
        },
        get_data: function () {
            var that = this;
            var options = {};
            options.action = "getsbusersummary";
            options.QueryTime = that.form.startMonth + '-01';
            console.log(JSON.stringify(options));
            ns.post(options, function (succeed, data, err) {
                console.log(JSON.stringify(succeed));
                console.log(JSON.stringify(data));
                console.log(JSON.stringify(err));
                if (succeed) {
                    var data = data.data;
                    that.list[0].count = data.AllComplateCount;
                    //巡检任务数
                    that.list[1].count = data.DeviceCheck.Count;
                    that.list[2].count = data.DeviceCheck.NormalCount;
                    that.list[3].count = data.DeviceCheck.TimeOutCount;
                    that.list[3].overtime = data.DeviceCheck.TimeOutPercent;
                    that.list[4].count = data.DeviceCheck.DeviceCount;
                    that.list[4].normalCount = data.DeviceCheck.DeviceNormalCount;
                    that.list[4].abnormalCount = data.DeviceCheck.DeviceNoNormalCount;
                    //维保任务数
                    that.list[5].count = data.DeviceRepair.Count;
                    that.list[6].count = data.DeviceRepair.NormalCount;
                    that.list[7].count = data.DeviceRepair.TimeOutCount;
                    that.list[7].overtime = data.DeviceRepair.TimeOutPercent;
                    that.list[8].count = data.DeviceRepair.DeviceCount;
                    that.list[8].normalCount = data.DeviceRepair.DeviceNormalCount;
                    that.list[8].abnormalCount = data.DeviceRepair.DeviceNoNormalCount;

                    //临时作业记录
                    that.list3[0].count = data.Temp.Count || 0;
                    that.list3[1].count = data.Temp.CheckTempCount || 0;
                    that.list3[1].normalCount = data.Temp.CheckTempNormalCount || 0;
                    that.list3[1].abnormalCount = data.Temp.CheckTempNoNormalCount || 0;
                    that.list3[2].count = data.Temp.repairTempCount || 0;
                    that.list3[2].normalCount = data.Temp.repairTempNormalCount || 0;
                    that.list3[2].abnormalCount = data.Temp.repairTempNoNormalCount || 0;
                    console.log('临时作业记录');
                    console.log(JSON.stringify(that.list3));
                } else if (err) {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            }, {
                toast: true
            });

        },
        do_open_task: function () {
            var that = this;
            ns.openWin('equipment_tasklist', '设备任务列表', {
                ProjectID: that.form.ProjectID,
                ProjectName: that.form.ProjectName,
                startMonth: that.form.startMonth,
            });
        },
        //跳转临时工作记录
        do_open_task_time: function () {
            var that = this;
            var title = '临时作业记录';
            var url = 'equipment_tasklist_record';
            ns.openWin(url, title, {
                ProjectID: that.form.ProjectID,
                ProjectName: that.form.ProjectName,
                startMonth: that.form.startMonth,
                IsAnalysis: false,
            });
        },
    }
});
apiready = function () {
    api.parseTapmode();
    ns = window.Foresight.Util;
    app.form.ID = api.pageParam.id || 0;
    //获取当前登录人姓名
    var username = api.getPrefs({
        sync: true,
        key: 'username'
    });
    app.UserName = username;
    app.minDate = new Date(moment(new Date()).add(-10, 'y'));
    app.maxDate = new Date(moment(new Date()).add(10, 'y'));
    app.currentDate = new Date();
    app.onConfirm(app.currentDate);
}
